package cn.jluzh.blog.mapper;

import cn.jluzh.blog.modules.article.entity.SysArticle;
import cn.jluzh.blog.modules.article.entity.SysArticleArchives;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SysArticleMapper extends BaseMapper<SysArticle> {

    @Select("select * from sys_article")
    List<SysArticle> getAllArticle();

    @Select("select * from sys_article where category_id =#{categoryId}")
    List<SysArticle> getArtByCateId(Integer categoryId);

    @Select("select sa.* from sys_article_tag sat JOIN sys_article sa on sa.id = sat.article_id\n" +
            "        where sat.tag_id = #{tagId}")
    List<SysArticle> getArtByTagId(Integer tagId);

    @Select("select year(create_time) as year,month(create_time) as month,count(*) as count from sys_article\n" +
            "        group by year(create_time),month(create_time)\n" +
            "        limit 0,#{limit}")
    List<SysArticleArchives> queyArticleArchives(int limit);

    @Select("select * from sys_article where title like CONCAT('%',#{query},'%')")
    List<SysArticle> getAllArticleByTitle(@Param("query") String query);

}
